home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6083 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Binary files ?
  5. Date: 22 Feb 1996 07:59 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <22FEB199607593247@erich.triumf.ca>
  9. References: <4gheee$bvr@ci.ist.utl.pt>
  10. NNTP-Posting-Host: erich.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <4gheee$bvr@ci.ist.utl.pt>, l40128@alfa.ist.utl.pt (delphis) writes...
  14. >      I program in c a couple of years but i never figure out this basic 
  15. >question : how to work with binary files ? basically, what i want to do 
  16. >is writing a matrix to a file and read it back but when i try the 
  17. >following code in dos the matrix comes all gobled, but works fine in unix!
  18. >      Can anyone tell me whats wrong with this ? I have been using text files
  19. >and they dont give any troble at all!
  20.  
  21. ># include <stdio.h>
  22. >void main()
  23.  
  24. to avoid flames on comp.lang.c (and because the C standard say so) main()
  25. _must_ return an int (then you need a return 0; at the end)
  26. >{
  27. > /*write file*/
  28. > int n;
  29. > unsigned char mat[200]; 
  30. > FILE *f=fopen("teste","w"); /*do i have to use the CREATE before this ?*/
  31.  
  32. In DOS, if you want a binary file, you must open it with "wb" or "rb".
  33.  
  34.  
  35. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  36. Internet: bennett@triumf.ca         | of one another only when one can be
  37. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  38. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  39. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  40.  
  41.  
  42.  
  43.  
  44.  
  45.